package test.testList;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class ModifyFileContent {
    public static void main(String[] args) {
        //String path = "E:\\tda\\trust-tda-biz-server";
        String path = "E:\\tda\\trust-tda-biz-hui\\src\\biz\\trust-tda-biz";

        Map<String,String> replaceMap = new HashMap<>();
        replaceMap.put("busin_pty","bpty");
        replaceMap.put("BUSIN_PTY","BPTY");
        replaceMap.put("BusinPty","Bpty");
        replaceMap.put("businPty","bpty");

        replaceMap.put("busin_unit","bunit");
        replaceMap.put("BUSIN_UNIT","BUNIT");
        replaceMap.put("BusinUnit","Bunit");
        replaceMap.put("businUnit","bunit");

        replaceMap.put("busin_role","brole");
        replaceMap.put("BUSIN_ROLE","BROLE");
        replaceMap.put("BusinRole","Brole");
        replaceMap.put("businRole","brole");

        replaceMap.put("busin_prtc","bprtc");
        replaceMap.put("BUSIN_PRTC","BPRTC");
        replaceMap.put("BusinPrtc","Bprtc");
        replaceMap.put("businPrtc","bprtc");

        replaceMap.put("busin_dept","bdept");
        replaceMap.put("BUSIN_DEPT","BDEPT");
        replaceMap.put("BusinDept","Bdept");
        replaceMap.put("businDept","bdept");

        replaceMap.put("busin_sys","bsys");
        replaceMap.put("BUSIN_SYS","BSYS");
        replaceMap.put("BusinSys","Bsys");
        replaceMap.put("businSys","bsys");

        replaceMap.put("busin_market","bmarket");
        replaceMap.put("BUSIN_MARKET","BMARKET");
        replaceMap.put("BusinMarket","Bmarket");
        replaceMap.put("businMarket","bmarket");

        try {
            readFile(path,replaceMap);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }





    public static void readFile(String path,Map<String,String> replaceMap) throws Exception{
        File file = new File(path);
        File[] tempList = file.listFiles();
        String separator = File.separator;
        /* "\\trust-tda-biz-server\\.git\" */
        //String gitPath = separator +"trust-tda-biz-server" + separator +".git";
        String gitPath = separator +"trust-tda-biz" + separator +".git";
        String gitPath1 = separator +"trust-tda-biz" + separator +".githooks";

        /* "\\trust-tda-biz-server\\schema\\" */
        String limitPath = separator +"trust-tda-biz-server"+separator+"schema"+separator;

        if(tempList != null && tempList.length > 0) {
            for (int i = 0; i < tempList.length; i++) {
                File file1 = tempList[i];
                String filePath = file1.getPath();
                //文件
                if (tempList[i].isFile()) {
                    if(filePath.contains(limitPath)){
                        FileContent.replaceText(filePath,replaceMap,"gbk");
                    }else {
                        FileContent.replaceText(filePath,replaceMap,"utf-8");
                    }
                }
                //文件夹
                if (tempList[i].isDirectory() && !filePath.contains(gitPath) && !filePath.contains(gitPath1)) {
                    //递归调用
                    readFile(filePath,replaceMap);
                }
            }
        }
    }
}
